package com.yinni.controller.sys;

import com.yinni.model.sys.MessageEntity;
import com.yinni.service.sys.WelcomeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class WelcomeController {

    private Logger log = LoggerFactory.getLogger(WelcomeController.class);

    @Resource(name = "welcomeServiceImpl")
    private WelcomeService welcomeService;

    /**
     * 新建留言信息
     *
     * @param
     * @return
     */
    @PostMapping(value = "/welcome/message")
    public MessageEntity insertMessage(@RequestBody MessageEntity messageEntity) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = df.format(new Date());
        messageEntity.setCreate_time(date);
        welcomeService.insertMessage(messageEntity);
        log.info("insert message success!" + messageEntity.toString());
        return messageEntity;
    }


}
